// pages/courses/courses.ts
const Navigation = require('../../utils/navigation.js')

Page({
  data: {
    currentTime: '09:46',
    toggleOn: true,
    recommendedResources: [
      {
        id: 1,
        title: '公众号变现课:账号搭建+内容运营+商业变现+月增',
        price: '9.90积分',
        date: '2025-09-17',
        level: '初级',
        views: '1013人查看',
        image: '💻'
      },
      {
        id: 2,
        title: 'Coze扣子工作流一键生成道家玄学短视频,实战保姆级',
        price: '9.90积分',
        date: '2025-09-17',
        level: '初级',
        views: '1083人查看',
        image: '☁️'
      }
    ],
    latestResources: [
      {
        id: 3,
        title: '小红书冷门项目:一本绝版书,轻松赚99元,月入2W+不是梦!',
        price: '9.90积分',
        date: '2025-09-17',
        level: '初级',
        views: '866人查看',
        image: '📚'
      },
      {
        id: 4,
        title: '公众号变现课:账号搭建+内容运营+商业变现+月增粉5000+变现转化提升4倍',
        price: '9.90积分',
        date: '2025-09-17',
        level: '初级',
        views: '1013人查看',
        image: '💻'
      },
      {
        id: 5,
        title: '潮式无厘头抖音变现课,独创工业化生产流程,单号月收益2万+',
        price: '9.90积分',
        date: '2025-09-17',
        level: '初级',
        views: '1060人查看',
        image: '🎵'
      },
      {
        id: 6,
        title: 'Coze扣子工作流一键生成道家玄学视频,实战保姆级教程',
        price: '9.90积分',
        date: '2025-09-17',
        level: '初级',
        views: '1083人查看',
        image: '☁️'
      }
    ]
  },

  onLoad() {
    this.updateTime();
  },

  onShow() {
    this.updateTime();
  },

  updateTime() {
    const now = new Date();
    const time = now.getHours().toString().padStart(2, '0') + ':' + 
                 now.getMinutes().toString().padStart(2, '0');
    this.setData({
      currentTime: time
    });
  },

  onToggleTap() {
    this.setData({
      toggleOn: !this.data.toggleOn
    });
    wx.showToast({
      title: this.data.toggleOn ? '已开启' : '已关闭',
      icon: 'none'
    });
  },

  onResourceTap(e: any) {
    const resource = e.currentTarget.dataset.resource;
    wx.showToast({
      title: `查看${resource.title}`,
      icon: 'none'
    });
  },

  onTabTap(e: any) {
    const page = e.currentTarget.dataset.page;
    Navigation.switchTab('courses', page);
  }
});
